package com.qy127.controller;

import com.alibaba.fastjson.JSON;
import com.qy127.dao.impl.ResultDaoImpl;
import com.qy127.entity.Resultt;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;


@WebServlet("/book")
public class LibrayServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");

        ResultDaoImpl resultDao = new ResultDaoImpl();
        int i = resultDao.selCount();//获取到的行数

        List<Map> bookAll = resultDao.getBookAll();//获取所有list<map> 类型的图书信息

        Resultt result = new Resultt(i, bookAll);//将查询到的数据封装成layui需要的格式  0;'',count,data[{},{}]
        String s = JSON.toJSONString(result);//将获取到的数据转换JSON字符串形式

        PrintWriter writer = resp.getWriter();
        writer.write(s);
       /*req.setAttribute("s",s);
        req.getRequestDispatcher("book.jsp").forward(req,resp);*/

    }
    protected void serce(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");

        ResultDaoImpl resultDao = new ResultDaoImpl();
        int i = resultDao.selCount();//获取到的行数

        List<Map> bookAll = resultDao.getBookAll();//获取所有list<map> 类型的图书信息

        Resultt result = new Resultt(i, bookAll);//将查询到的数据封装成layui需要的格式  0;'',count,data[{},{}]
        String s = JSON.toJSONString(result);//将获取到的数据转换JSON字符串形式

        PrintWriter writer = resp.getWriter();
        writer.write(s);
       /*req.setAttribute("s",s);
        req.getRequestDispatcher("book.jsp").forward(req,resp);*/

    }
    protected void rvice(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");

        ResultDaoImpl resultDao = new ResultDaoImpl();
        int i = resultDao.selCount();//获取到的行数

        List<Map> bookAll = resultDao.getBookAll();//获取所有list<map> 类型的图书信息

        Resultt result = new Resultt(i, bookAll);//将查询到的数据封装成layui需要的格式  0;'',count,data[{},{}]
        String s = JSON.toJSONString(result);//将获取到的数据转换JSON字符串形式

        PrintWriter writer = resp.getWriter();
        writer.write(s);
       /*req.setAttribute("s",s);
        req.getRequestDispatcher("book.jsp").forward(req,resp);*/

    }
}
